package com.example.demo.zaqizabatest;

import org.springframework.util.IdGenerator;
import org.springframework.util.SimpleIdGenerator;

import java.util.UUID;

/**
 * @ClassName ThreadLocalIdGenerator
 * @Author l42142
 * @Date 2021/3/3 14:33
 * @Description TODO
 * @Version 1.0
 **/
public class ThreadLocalIdGenerator{
    private static final ThreadLocal<IdGenerator> ID_GENERATOR = new ThreadLocal<IdGenerator>(){
        protected IdGenerator initalValue(){
            return new SimpleIdGenerator();//IdGenerator 是个初始int value =0,然后getNext(){  return value++}
        }
    };
    public static UUID getNext(){
        final UUID uuid = ID_GENERATOR.get().generateId();
        ID_GENERATOR.remove();
        return uuid;
    }

    private ThreadLocal myThreadLocal = new ThreadLocal <String>(){
        @Override
        protected String initialValue() {
            return "This is the initial value";
        }
    };

}
